/*
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "mokoko.h"
#include "collections.h"
#include "config.h"
#include "playback.h"
#include "debug.h"
#include "mokoko_music_panel.h"

static int
exit_handler(void *data, int type, void *event)
{
        debug("Exit handler\n");
        mokoko_media_deinit();
        ecore_main_loop_quit();
        return 1;
}

int main (int argc, char **argv) {
        if (!ecore_init()) { printf("failed to init ecore\n"); return -1; }
        ecore_event_handler_add(ECORE_EVENT_SIGNAL_HUP, exit_handler, NULL);
        ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_handler, NULL);

        // init E
        if (!ecore_init()) {
                error("failed to init ecore\n");
                return -1; 
        }
        if (!ecore_evas_init()) {
                error("failed to init ecore_evas\n");
                return -1; 
        }
        if (!edje_init()) {
                error("failed to init edje\n");
                return -1; 
        }
        if (!etk_init(argc, argv)) {
                error("failed to init etk\n");
                return -1;
        }

        if(!mokoko_media_init(argc, argv)) return FALSE;
        config_read();

        /* Create a Collections which contains few songs for testing */
        Collections *C = get_all_songs();
        init_music_panel(C);

        ecore_main_loop_begin();
        // End
        ecore_main_loop_quit();
        mokoko_media_deinit();
        return 0;
}
